package com.erji.common.mybatis.persistence;

import com.erji.common.mybatis.entity.SuperModel;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collection;
import java.util.List;

public interface SuperService<T extends SuperModel> {
    T fetchById(String id);

    T getById(String id);

    T updateById(T entity);

    T saveOrUpdate(T entity);

    T save(T entity);

    @Transactional(
            rollbackFor = {Exception.class}
    )
    default boolean saveOrUpdateBatch(Collection<T> entityList) {
        return this.saveOrUpdateBatch(entityList, 1000);
    }

    boolean saveOrUpdateBatch(Collection<T> entityList, int batchSize);

    boolean saveBatch(Collection<T> entityList, int batchSize);

    int removeById(String id);

    int removeByIds(Collection<String> idList);

    int physicalRemoveById(String id);

    int physicalRemoveByIds(Collection<String> idList);

    List<T> findAll();

    boolean checkPropertyDuplicate(String sourceProperty, String targetProperty, ISelectCount select);
}
